package csu.web.mypetstore.service;

import csu.web.mypetstore.domain.Account;
import csu.web.mypetstore.domain.Cart;
import csu.web.mypetstore.domain.MyCart;
import csu.web.mypetstore.persistence.AccountDao;
import csu.web.mypetstore.persistence.impl.AccountDaoImpl;

import java.util.List;

public class AccountService {
    private AccountDao accountDao;


    public AccountService(){
        this.accountDao = new AccountDaoImpl();
    }
    public Account getAccount(String username, String password) {
        Account account = new Account();
        account.setUsername(username);
        account.setPassword(password);
        return accountDao.getAccountByUsernameAndPassword(account);
    }
    public Account getAccountByUsername(String username){
        return accountDao.getAccountByUsername(username);
    }
    public void ReserveCart(Account account, Cart cart){
        accountDao.reserveCart(account,cart);
    }
    public Cart ReadMyCart(Account account,Cart cart){
        return accountDao.readMyCart(account,cart);
    }
    public void updateAccount(Account account){
         accountDao.updateaccount(account);
    }
    public void changeAccount(Account account){
        accountDao.ChangeAccount(account);
    }



    //建立新的账户
    public void createAccount(String username,String password,String email,String firstname,String lastname,String status,String addr1,String addr2,String state,String phone,String zip,String country,String city,String favouriteCategoryId,String listOption,String bannerOption){
        Account account = new Account();
        account.setUsername(username);
        account.setPassword(password);
        account.setEmail(email);
        account.setCity(city);
        account.setAddress1(addr1);
        account.setAddress2(addr2);
        account.setCountry(country);
        account.setFirstName(firstname);
        account.setLastName(lastname);
        account.setStatus(status);
        account.setState(state);
        account.setPhone(phone);
        account.setZip(zip);
        account.setFavouriteCategoryId(favouriteCategoryId);
        account.setLanguagePreference("English");
        account.setListOption((listOption.equals("1") ));
        account.setBannerOption((bannerOption.equals("1") ));
        accountDao.updateAccount(account);
        accountDao.updateSignon(account);
        accountDao.updateProfile(account);
    }
}